import geopandas as gpd
import pandas as pd
import datetime

inf=gpd.read_file('C:/Users/18295335197/Desktop/test/全省病例.geojson')
inf['onset_date']=pd.to_datetime(inf['onset_date'])
inf['discharge_date']=pd.to_datetime(inf['discharge_date'])
inf['Diagnosis_date']=pd.to_datetime(inf['Diagnosis_date'])
oyinf=inf.query("discharge_date!='2001-01-01'")
yinf=oyinf
yinf['days']=((yinf['discharge_date']-yinf['onset_date'])/pd.Timedelta(1, 'D')).fillna(0).astype(int)
yinf_mean=int(yinf['days'].mean())

xinf=inf.query("discharge_date=='2001-01-01'")

xinf1=xinf.query("severity=='危重型' or severity=='重型'")
xinf1['dead_date']=xinf1['onset_date']+datetime.timedelta(18)
xinf1['discharge_date']=pd.NaT

xinf2=xinf.query("severity!='危重型' or severity!='重型'")
xinf2['discharge_date']=xinf2['onset_date']+datetime.timedelta(yinf_mean)

new_inf= pd.concat([oyinf,xinf1,xinf2,], ignore_index=True)
new_inf.to_file('C:/Users/18295335197/Desktop/test/全省病例日期恢复.geojson',driver='GeoJSON', encoding='utf-8')


